package com.ruoyi.business.api;

import cn.hutool.json.JSONArray;
import com.ruoyi.business.domain.TaskUserTrajectory;
import com.ruoyi.business.request.ApiTrajectoryCreateReq;
import com.ruoyi.business.request.ApiTrajectoryQueryReq;
import com.ruoyi.business.response.ApiTrajectoryRes;
import com.ruoyi.business.service.ITaskUserTrajectoryService;
import com.ruoyi.common.core.domain.PageResult;
import com.ruoyi.common.core.domain.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author liutao
 * @version 1.0
 * @description: 行程轨迹接口
 * @date 2024/3/20 20:33
 */

@RestController
@RequestMapping("/api/trajectory")
public class TrajectoryApi {

    @Resource
    private ITaskUserTrajectoryService taskUserTrajectoryService;

    @GetMapping("/page")
    public R<PageResult<ApiTrajectoryRes>> pageTrajectory(ApiTrajectoryQueryReq req) {
        return R.ok(taskUserTrajectoryService.pageTrajectory(req));
    }

    /**
     * 根据调研计划获取轨迹列表
     * @param researchPlanId
     * @return
     */
    @GetMapping("/list")
    public R<List<List<BigDecimal>>> getTrajectoryList(@RequestParam Long researchPlanId, @RequestParam Integer version) {
//    public R<Map<Integer,List<TaskUserTrajectory>>> getTrajectoryList(@PathVariable Long researchPlanId) {
        return R.ok(taskUserTrajectoryService.getTrajectoryList(researchPlanId, version));
//        return R.ok(taskUserTrajectoryService.getTrajectoryListMap(researchPlanId));
    }

    /**
     * 创建形成轨迹
     * @param req
     * @return
     */
    @PostMapping("/create")
    public R<Boolean> create(@RequestBody @Validated ApiTrajectoryCreateReq req) {
        return R.ok(taskUserTrajectoryService.create(req));
    }

    /**
     * 同步行程轨迹到数据库
     * @param researchPlanId
     * @return
     */
    @PostMapping("/sync/{researchPlanId}")
    public R<Boolean> sync(@PathVariable Long researchPlanId) {
        return R.ok(taskUserTrajectoryService.sync(researchPlanId));
    }
}
